class Solution {
private:
    stack<int> s1;//储存元素的栈
    stack<int> minstack;//最小栈
public:
    void push(int value) {
        s1.push(value);
        if(minstack.empty())
        {
            minstack.push(value);
            return ;
        }
        if(value<minstack.top())
        {
            minstack.push(value);
            return ;
        }
        minstack.push(minstack.top());
    }
    void pop() 
    {
        int top = s1.top();
        s1.pop();
        while(top == minstack.top())
        {
            minstack.pop();
            if(minstack.size() == s1.size())
            {
                break;
            }
        }    
    }
    int top() {
        return s1.top();
    }
    int min() {
        return minstack.top();
    }
};